package com.myexam.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.myexam.model.Student;
import com.myexam.service.StudentService;
import com.opensymphony.xwork2.ActionSupport;


@Controller
@Scope("prototype")
public class StudentAddAction extends ActionSupport {

	
	private static final long serialVersionUID = -8508678752856841094L;
	private String studentID;
	private String studentName;
	private String studentPass;
	private String sclass;
	@Autowired
	private StudentService studentService;
	public String getStudentID() {
		return studentID;
	}
	public void setStudentID(String studentID) {
		this.studentID = studentID;
	}
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getStudentPass() {
		return studentPass;
	}
	public void setStudentPass(String studentPass) {
		this.studentPass = studentPass;
	}
	public String getSclass() {
		return sclass;
	}
	public void setSclass(String sclass) {
		this.sclass = sclass;
	}
	
	public String execute() throws Exception{
		Student student = new Student();
		student.setStudentID(studentID);
		student.setStudentName(studentName);
		student.setPassword(studentPass);
		student.setSclass(sclass);
		if(studentService.saveStudent(student)){
			return SUCCESS;
		}else {
			//this.addActionError("");
			return INPUT;
		}
	}
	
}
